package com.csx.saas.merchant.tenant.controller;

import com.csx.saas.merchant.tenant.entity.Tenant;
import com.csx.saas.merchant.tenant.dto.TenantSaveDTO;
import com.csx.saas.merchant.tenant.dto.TenantUpdateDTO;
import com.csx.saas.merchant.tenant.dto.TenantPageQuery;
import com.csx.saas.merchant.tenant.service.TenantService;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.csx.basic.base.controller.SuperCacheController;
import com.csx.basic.base.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import com.csx.basic.annotation.security.PreAuth;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 企业
 * </p>
 *
 * @author ChenSongXin
 * @date 2021-03-15
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/tenant")
@Api(value = "Tenant", tags = "企业")
@PreAuth(replace = "merchant:tenant:")
public class TenantController extends SuperCacheController<TenantService, Long, Tenant, TenantPageQuery, TenantSaveDTO, TenantUpdateDTO> {

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<Tenant> tenantList = list.stream().map((map) -> {
            Tenant tenant = Tenant.builder().build();
            //TODO 请在这里完成转换
            return tenant;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(tenantList));
    }
}
